package com.zjitc.order;

import com.sun.org.apache.xpath.internal.SourceTree;
import com.sun.org.apache.xpath.internal.operations.Or;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/18 13:57
 * @description:
 */
public class QueueOrderInfo {

  private final ArrayBlockingQueue<OrderInfo> queue = new ArrayBlockingQueue<>(500);

  /**
   * 单例对象
   */
  public static final QueueOrderInfo Instance = new QueueOrderInfo();

  private QueueOrderInfo() {}

  /**
   * 弹出队列中的第一个元素
   * @return
   * @throws InterruptedException
   */
  public OrderInfo take() throws InterruptedException {
    return queue.take();
  }

  /**
   * 向队列的尾部添加一个元素
   * @param info
   */
  public void add(OrderInfo info) {
    queue.add(info);
    /**********************************************/
    // System.out.println("============收到用户的订单信息，并已经存入到队列中了" + info.toString());
  }

  public static void main(String[] args) throws InterruptedException {
    QueueOrderInfo.Instance.add(new OrderInfo("1", 1));
    QueueOrderInfo.Instance.add(new OrderInfo("2", 1));


    System.out.println(QueueOrderInfo.Instance.take());
    System.out.println(QueueOrderInfo.Instance.take());

    System.out.println(QueueOrderInfo.Instance.take());
  }

}
